package cn.tedu.tmall.passport.controller;

import cn.tedu.tmall.common.web.JsonResult;
import cn.tedu.tmall.passport.pojo.param.UserLoginInfoParam;
import cn.tedu.tmall.passport.pojo.vo.UserLoginResultVo;
import cn.tedu.tmall.passport.service.IUserService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@Api(tags = "用户管理")
@RestController
@RequestMapping("/users")
public class UserController {
    @Autowired
    private IUserService service;

    @ApiOperation("用户登录")
    @ApiOperationSupport(order = 100)
    @PostMapping("/login")
    public JsonResult login(@Valid UserLoginInfoParam userLoginInfoParam,
                            @ApiIgnore HttpServletRequest request){
        System.out.println(userLoginInfoParam);
        String remoteAddr = request.getRemoteAddr();
        String user_agent = request.getHeader("User_Agent");
        UserLoginResultVo resultVo = service.login(userLoginInfoParam,remoteAddr,user_agent);
        return JsonResult.ok(resultVo);
    }


}
